home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / comm / mebbs / directdl.lha / DirectDL.c < prev    next >
C/C++ Source or Header  |  1994-04-26  |  5KB  |  175 lines

  1. /* DirectDL.c this program will allow specifying a file with the */
  2. /* complete pathname and Mebbsnet will xfer the file and adjust  */
  3. /* the user's stats to reflect the download.                     */
  4. /*                                                               */
  5. /*    WARNING WARNING WARNING WARNING WARNING WARNING WARNING    */
  6. /*                                                               */
  7. /* This door was written to allow me to easily download files    */
  8. /* remotely that I did not have in the BBS file catalogs.        */
  9. /* There are significant security risks involved in allowing     */
  10. /* indiscriminate downloading of your files. For example         */
  11. /* mebbsnet.con and the user.dat file contain confidential       */
  12. /* information that could leave your BBS or some of your user's  */
  13. /* confidential information vulnerable.                          */
  14. /*                                                               */
  15. /* For this reason a security.cfg file has been provided which   */
  16. /* should prevent the transfer of your user.dat and mebbsnet.con */
  17. /* files. Additional security should be provided by linking this */
  18. /* door program with access restrictions (ie MINACCESS 31)       */
  19. /*                                                               */
  20. /* I eventually plan on expanding this program to allow its use  */
  21. /* in a CD-ROM file door.                                        */
  22.  
  23.  
  24. #include <exec/types.h>
  25. #include <exec/libraries.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <stdio.h>
  29. #include <fcntl.h>
  30. #include <dos.h>
  31. #include <dos/dos.h>
  32. #include <proto/dos.h>
  33. #include <proto/exec.h>
  34. #include <ctype.h>
  35. #include "mebbsutility.h"
  36.  
  37. #define DoorName "DirectDL"
  38.  
  39. struct Library *MEBBSUtilityBase = NULL;
  40.  
  41. void *LinkData;
  42.  
  43. void main (int, char **);
  44. void CleanUp(void);
  45. struct FileInfoBlock fileInfo;
  46.  
  47. BYTE FileName[255];
  48. int error;
  49.  
  50.  
  51. void main(int argc, char *argv[])
  52. {
  53.  
  54.    char PassString[120];
  55.    char WorkString[120];
  56.  
  57.    UWORD LineNumber;
  58.    UWORD Data=0;
  59.    LONG NewData=0;
  60.    LONG FileLength;
  61.    LONG NewFiles=0;
  62.    FILE *fptr, *fopen();
  63.    char xfile[256];
  64.    char test[256];
  65.    char *p;
  66.    int x;
  67.    int q;
  68.  
  69.    LineNumber = atoi(argv[1]);
  70.  
  71.    if(!(MEBBSUtilityBase = OpenLibrary("mebbsutility.library",1L)))
  72.  
  73.    {
  74.       printf("\nCould not open mebbsutility.library\n");
  75.       exit(20);
  76.    }
  77.  
  78.    if(MEBBSUtilityBase->lib_Revision < 1)
  79.    {
  80.       CleanUp();
  81.    }
  82.  
  83.    if(!(LinkData = LinkDoor(DoorName,LineNumber)))
  84.    CleanUp();
  85.  
  86.    if(CheckCarrier(LinkData))CleanUp();
  87.    PrintString(LinkData,"",1);
  88.    PrintString(LinkData,"",1);
  89.    PrintString(LinkData,"Direct Download facility by Bob Scheel.",1);
  90.    PrintString(LinkData,"      Mebbsnet developer #M2017",1);
  91.    PrintString(LinkData,"",1);
  92.    NewData = GetUserInfo(LinkData,PassString,Data,SND_DOWNLOADBYTES);
  93.    NewFiles = GetUserInfo(LinkData,PassString,Data,SND_FILESDOWNLOADED);
  94.    sprintf(WorkString,"You have downloaded %ld bytes and %ld files.\n",NewData,NewFiles);
  95.    PrintString(LinkData,WorkString,1);
  96.    HotKeyPrompt(LinkData," Do you wish to download (y/N): ",PassString);
  97.    if(CheckCarrier(LinkData))CleanUp();
  98.    PrintString(LinkData,"",1);
  99.    strupr(PassString);
  100.    switch(PassString[0])
  101.    {
  102.       case 'Y':
  103.  
  104.       Prompt(LinkData,"\nEnter full pathname ->",FileName,70);
  105.         if(CheckCarrier(LinkData))CleanUp();
  106.  
  107.       if(FileName[0])
  108.         {
  109.          sprintf(xfile,"Doors:Directdl/Security.cfg");
  110.          p = strupr(FileName);
  111.          fptr=fopen(xfile,"ra");
  112.          if(CheckCarrier(LinkData))CleanUp();
  113.          if (fptr==0)
  114.            {
  115.             PrintString(LinkData,"* * * * * * * WARNING * * * * * * * * * *\n",1);
  116.             PrintString(LinkData,"    Security file couldn't be opened!\n",1);
  117.             PrintString(LinkData,"Program aborting to protect BBS security!\n",1);
  118.             CleanUp();
  119.            }
  120.          do
  121.            {
  122.             q = fscanf(fptr,"%s",test);
  123.             if (q>0)
  124.               {
  125.                p = strupr(test);
  126.                x = astcsma(FileName,test);
  127.                if (x) {
  128.                  sprintf(PassString,"%s is a restricted file. Access denied.",FileName);
  129.                  PrintString(LinkData,PassString,1);
  130.                  CleanUp();
  131.                  }
  132.               }
  133.            }
  134.          while (q>0);
  135.          fclose(fptr);
  136.          error = dfind(&fileInfo,FileName,0);
  137.          if (error == 0)
  138.          {
  139.          FileLength = fileInfo.fib_Size;
  140.          SendFile(LinkData,FileName);
  141.          NewData = FileLength + NewData;
  142.          NewFiles = NewFiles + 1;
  143.          EditUserInfo(LinkData,PassString,NewData,SND_DOWNLOADBYTES);
  144.          NewData = GetUserInfo(LinkData,PassString,Data,SND_DOWNLOADBYTES);
  145.          EditUserInfo(LinkData,PassString,NewFiles,SND_FILESDOWNLOADED);
  146.          NewFiles = GetUserInfo(LinkData,PassString,Data,SND_FILESDOWNLOADED);
  147.          PrintString(LinkData,"\n\n\nDownload Complete.",1);
  148.          if(CheckCarrier(LinkData))CleanUp();
  149.          sprintf(WorkString,"You have now downloaded %ld bytes and %ld files.\n",NewData,NewFiles);
  150.          PrintString(LinkData,WorkString,1);
  151.          if(CheckCarrier(LinkData))CleanUp();
  152.          }
  153.       }
  154.  
  155.       break;
  156.  
  157.       default:
  158.       PrintString(LinkData,"\n\n  Changed your mind huh ;-)\n",1);
  159.       break;
  160.    }
  161.  
  162.    CleanUp();
  163.  
  164. }
  165.  
  166. void CleanUp(void)
  167. {
  168.    if(LinkData)CloseDoor(LinkData);
  169.    if(MEBBSUtilityBase)CloseLibrary(MEBBSUtilityBase);
  170.    exit(0);
  171. }
  172.  
  173.  
  174.  
  175.